﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

namespace YArchitech.MEP.Electric.CableLay
{
	public class ElectricalFilter : ISelectionFilter
	{
		bool ISelectionFilter.AllowElement(Element element)
		{
			FamilyInstance familyInstance = element as FamilyInstance;
			if (familyInstance == null || familyInstance.MEPModel == null || familyInstance.MEPModel.ConnectorManager == null)
			{
				return false;
			}
			ConnectorSet connectors = familyInstance.MEPModel.ConnectorManager.Connectors;
			if (connectors == null || connectors.Size <= 0)
			{
				return false;
			}
			ConnectorSetIterator connectorSetIterator = connectors.ForwardIterator();
			while (connectorSetIterator.MoveNext())
			{
				if ((connectorSetIterator.Current as Connector).Domain == (Autodesk.Revit.DB.Domain)2)
				{
					return true;
				}
			}
			return false;
		}

		bool ISelectionFilter.AllowReference(Reference reference, XYZ position)
		{
			return false;
		}
	}
}
